<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="../header.jsp"%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${systemName }</title>
    <link rel="shortcut icon" href="${contextPath}/resources/favicon.ico"> 
    <link href="${contextPath}/resources/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${contextPath}/resources/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <!-- Data Tables -->
    <link href="${contextPath}/resources/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="${contextPath}/resources/css/animate.min.css" rel="stylesheet">
    <link href="${contextPath}/resources/css/style.min.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
     <div class="ibox-content">
        <form action="${contextPath}/system/maker/list" class="form-horizontal" name="searchFrom"> 
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<a href="${contextPath}/system/goodCategory/addInit" class="btn btn-primary btn-xs">添加一级分类</a>
                        <table class="table table-striped table-hover dataTables-example">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>分类名称</th>
                                    <th>级别</th>
                                    <th>商家是否可用</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="category-table">
	                            <c:forEach items="${list}" var="category" varStatus="vs">  
								        <tr>  
								             <td class="category-father" category-id="${category.id}">
								             	<a href="#"><i class="fa fa-angle-down"></i></a>
								             </td>
								             <td>${category.title}</td> 
								             <td>
								             	<c:choose> 
								              		<c:when test="${category.level == 1}">一级分类</c:when>
								              	</c:choose>
								              	<c:choose> 
								              		<c:when test="${category.level == 2}">二级分类</c:when>
								              	</c:choose>
								              </td>
								             <td>
								             </td>  
								             <td>
								             	<c:choose> 
									                <c:when test="${category.id != 9999}">
									                	<a href="${contextPath}/system/goodCategory/addInit?parentId=${category.id}" class="btn btn-primary btn-xs">添加子分类</a>
									                </c:when>
									              </c:choose>
								              </td>
								         </tr> 
								         <c:forEach items="${category.childCategorys}" var="childCategory" varStatus="vsindex">
								         	<tr style="display:none;" class="category-child-${category.id}">  
								              <td></td>
								              <td>${childCategory.title}</td> 
								              <td>
								              	<c:choose> 
								              		<c:when test="${childCategory.level == 1}">一级分类</c:when>
								              	</c:choose>
								              	<c:choose> 
								              		<c:when test="${childCategory.level == 2}">二级分类</c:when>
								              	</c:choose>
								              </td>
								              <td>
								              	<c:choose> 
								              		<c:when test="${childCategory.shopUse == 0}">否</c:when>
								              	</c:choose>
								              	<c:choose> 
								              		<c:when test="${childCategory.shopUse == 1}"><span class="text-success">是</span></c:when>
								              	</c:choose>
								              </td>  
								              <td>
								              	  <%--设置为首页banner位展示  --%>
									              <c:choose>
									                <c:when test="${childCategory.isRecommendBanner == 0}">
									                <%--${contextPath}/system/goodCategory/addHotSell/${childCategory.id} --%>
									                	<button type="button" class="btn btn-primary btn-xs" onclick="showModal(${childCategory.id})">推荐到首页banner位</button>
									                </c:when>
									                <c:when test="${childCategory.isRecommendBanner == 1}">
									                	<a href="${contextPath}/system/goodCategory/cancelHomeBanner/${childCategory.id}" class="btn btn-primary btn-xs">删除首页banner位推荐</a>
									                </c:when>
									              </c:choose>
								              	  <%--热卖 --%>
									              <c:choose>
									                <c:when test="${childCategory.addHot == 0}">
									                	<a href="${contextPath}/system/goodCategory/addHotSell/${childCategory.id}" class="btn btn-primary btn-xs">添加到热卖分类</a>
									                </c:when>
									                <c:when test="${childCategory.addHot == 1}">
									                	<a href="${contextPath}/system/goodCategory/cancelHotSell/${childCategory.id}" class="btn btn-primary btn-xs">从热卖分类中删除</a>
									                </c:when>
									              </c:choose>
									              <%--推荐到首页展示  --%>
									              <c:choose> 
									                <c:when test="${childCategory.recommend == 0}">
									                	<a href="${contextPath}/system/goodCategory/addFirstHomeComment/${childCategory.id}" class="btn btn-primary btn-xs">加入首页推荐</a>
									                </c:when> 
									                <c:when test="${childCategory.recommend == 1}">
									                	<a href="${contextPath}/system/goodCategory/cancelFirstHomeComment/${childCategory.id}" class="btn btn-primary btn-xs">删除主页推荐</a>
									                </c:when>
									              </c:choose>
									              <%--设置为商家可用分类 --%>
									              <c:choose> 
									                <c:when test="${childCategory.shopUse == 0}">
									                	<a href="${contextPath}/system/goodCategory/updateCategoryShopUse/${childCategory.id}" class="btn btn-primary btn-xs">设为商家可用</a>
									                </c:when>
									                <c:when test="${childCategory.shopUse == 1}">
									                	<a href="${contextPath}/system/goodCategory/cancelCategoryShopUse/${childCategory.id}" class="btn btn-primary btn-xs">取消商家可用</a>
									                </c:when>
									              </c:choose>
								              </td>
								            </tr> 
								         </c:forEach>
								</c:forEach>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        </form>
        </div>
    </div>
	<div class="modal inmodal" id="myModal4" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<form action="${contextPath }/system/goodCategory/addHomeBanner" class="form-horizontal" method="post" id="saveBannerImg" enctype="multipart/form-data">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<h4>上传Banner位图片</h4>
				</div>
				<div class="modal-body">
					<input type="file" name="file" class="form-control" id="bannerImg"/>
					<input type="hidden" name="categoryId"  id="categoryIdHiddenInput"/>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" onclick="recommendToBanner()">保存</button>
				</div>
			</div>
			</form>
		</div>
	</div>
	<script src="${contextPath}/resources/js/jquery.min.js?v=2.1.4"></script>
    <script src="${contextPath}/resources/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${contextPath}/resources/js/plugins/jeditable/jquery.jeditable.js"></script>
    <script src="${contextPath}/resources/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="${contextPath}/resources/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="${contextPath}/resources/js/content.min.js?v=1.0.0"></script>
	<script>
		var categoryId = 0;
		$(document).ready(function() {
			$("#category-table td.category-father").on("click", function() {
				var $btn = $(this).find('i');
				if ($btn.data('expand') == 0) {
					$btn.data('expand', 1);
				} else if ($btn.data('expand') == 1) {
					$btn.data('expand', 0);
				}
				var id = $(this).attr('category-id');
				$("#category-table tr.category-child-" + id).toggle(200);
			});
		});
		function recommendToBanner() {
			var bannerImg = $("#bannerImg").val();
			console.info(bannerImg);
			if(bannerImg == ''){
				alert("请选择图片");
				return false;
			}
			$("#categoryIdHiddenInput").val(categoryId);
			$("#saveBannerImg").submit();
		}
		function showModal(id){
			categoryId = id;
			$('#myModal4').modal('show')
		}
	</script>
</body>
</html>
